%MY_PLOT1DFFT calculates the Discrete Fourier Transform of a function f
%distributed along the x space. Then plots both the original function and
%its frequency distirbution.
%   To plot the frequency distribution as asked, we have to shift
%   it to center the zero frequency component on x=0. In order to do so we
%   first make sure that the median from the fdft distribution is zero and
%   then we swap the values: for example, the value at x=-6 and x=6 goes to
%   x=-1 and x=1, while x=-1 and x=1 goes to x=-6 and x=6 respectively.
function  my_plotDft1D( x,f,figName )

figure;

%Function plot
subplot(2,1,1);
plot(x,f);
title(figName);

%Discrete Fourier Transform
fdft = my_dft1D(f);
N = size(fdft,2);

%Make sure median is zero
x = (x - median(x));
fdft = (real(fdft) - median(real(fdft)));

%Get index from the center (median = 0))
center = floor(N/2);
if(fdft(center) ~= 0)
    center = center+1;  %supposed to get ceiling instead

%Scaling the frequencies
fdft(1:center) = abs(fdft(1:center)-min(fdft(1:center)));
fdft(center+1:N) = abs(fdft(center+1:N)-min(fdft(center+1:N)));

%Shift everything around
rightHalf = fdft(1:center);
leftHalf = flipud(fdft(center+1:N));

fdft = [leftHalf rightHalf];

%Histogram-like plot: centers,frequency
subplot(2,1,2);
bar(x,fdft);


end

